package com.jmb.api.common.enumPro;

import java.util.HashMap;
import java.util.Map;

public enum AssertOperator {
    EQ("=",  0),
    LT("<",  1),
    GT(">",  2),
    LE("<=",  3),
    GE(">=",  4),
    IN("in",  5),
    NE("!=",  6),
    RE("re",  7),

    // 兼容模式
    EQ_("eq",  0),
    EQ__("==",  0),
    LT_("lt",  1),
    GT_("gt",  2),
    LE_("le",  3),
    GE_("ge",  4),
    IN_("in",  5),
    NE_("ne",  6),
    RE_("re",  7),

    IS_NULL("isNull",  8),
    IS_NULL_("is_null",  8),
    NOT_NULL("notNull",  9),
    NOT_NULL_("not_null",  9),
    CONTAINS("contains",  10),
    IS_EMPTY("isEmpty",  11),
    IS_EMPTY_("is_empty",  11),
    IS_NOT_EMPTY("isNotEmpty",  12),
    IS_NOT_EMPTY_("is_not_empty",  12);

    private final String assertOperatorName;
    private final Integer assertOperatorType;

    // 预构建名称到类型的映射表（小写标准化）
    private static final Map<String, Integer> OPERATOR_MAP = new HashMap<>();

    static {
        for (AssertOperator operator : values()) {
            // 统一转换为小写，避免后续重复转换
            OPERATOR_MAP.put(operator.assertOperatorName.toLowerCase(), operator.assertOperatorType);
        }
    }

    public static Integer getAssertOperatorKey(String assertOperatorName) {
        // 查找时直接小写化输入名称，避免大小写敏感问题
        return OPERATOR_MAP.getOrDefault(assertOperatorName.toLowerCase(),  0);
    }

    AssertOperator(String assertOperatorName, Integer assertOperatorType) {
        this.assertOperatorName = assertOperatorName;
        this.assertOperatorType = assertOperatorType;
    }
}
